const answerButton  = document.querySelector('.answer-button');

answerButton.addEventListener('click', e => {
    const answers = document.querySelectorAll('.answer');
    if (e.target.textContent === '隐藏答案'){
        answerButton.textContent = '显示答案';
    }else {
        answerButton.textContent = '隐藏答案';
    }
    for (const answer of answers) {
        if (answer.style.display !== 'none'){
            answer.style.display = 'none';
        }
        else{
            answer.style.display = 'block';
        }
    }
});

const nav = document.querySelector('.nav');
const questions = document.querySelectorAll('.questions');

let count = 0;
for (let index = 1; index<=18; index++) {
    if (index === 3 || index === 9 || index === 15){
        continue;
    }

    const li = document.createElement('li');
    const a = document.createElement('a');
    a.href = '#' + questions[count].id;
    a.textContent = `第${index}章`;
    if (count === questions.length - 1){
        a.textContent = `测试题`;
    }
    li.appendChild(a);
    nav.appendChild(li);
    count ++;
}

const navA = document.querySelectorAll('.nav a');
for (const navAElement of navA) {
    navAElement.addEventListener('click', e => {
        for (const navAElement1 of navA) {
            navAElement1.style.backgroundColor = 'dodgerblue';
        }
        e.target.style.backgroundColor = 'orange';
    })
}

const homeBtn = document.querySelector('.to-home button');
homeBtn.addEventListener('click', function (e) {
    location.href = '../index.html';
})